from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app

from google.appengine.api import urlfetch

from xml.sax import saxutils, make_parser, SAXParseException
from xml.sax.handler import feature_namespaces, feature_namespace_prefixes
from xml.sax.saxutils import XMLGenerator
from xml.sax.xmlreader import AttributesImpl
from StringIO import StringIO
import xml.sax._exceptions
import sys

from ffOPML import FFOPML

def handle_result(rpc):
  result = rpc.get_result()
  print "<pre>"
  print result.content

# Use a helper function to define the scope of the callback.
def create_callback(rpc):
  return lambda: handle_result(rpc)

urls = ["http://feiss.be/rss"]
rpcs = []
for url in urls:
  rpc = urlfetch.create_rpc()
  rpc.callback = create_callback(rpc)
  urlfetch.make_fetch_call(rpc, url)
  rpcs.append(rpc)


# Finish all RPCs, and let callbacks process the results.
for rpc in rpcs:
  rpc.wait()


class MainPage(webapp.RequestHandler):
  def get(self):
    self.response.headers['Content-Type'] = 'text/plain'
    self.response.out.write('Hello, webapp World!')

application = webapp.WSGIApplication(
                                     [('/', MainPage)],
                                     debug=True)



def main():
  run_wsgi_app(application)

if __name__ == "__main__":
  main()
  
